// import axios from 'axios'
import vue from '../../main'

/* eslint-disable */
// const baseUrl = 'http://exam.sano1000.com:2009'
// const baseUrl = 'http://192.168.0.99:2012'
// const baseUrl = 'http://localhost:2012'
export default {
  isbool(param) {
    // console.log(param)
    if (param == '') {
      return false
    }
    if (param == []) {
      return false
    }
    if (param == "[]") {
      return false
    }
    if (param == undefined) {
      return false
    }
    if (param == 'undefined') {
      return false
    }
    if (param == {}) {
      return false
    }
    if (param == 0) {
      return false
    }
    if (param == "0") {
      return false
    }
    if (param == "null") {
      return false
    }
    if (param == null) {
      return false
    }
    return true
  },
  isTrue(param){return this.isbool(param)},
  str2time (str) {
    let date = new Date(str)
    return this.getDateTime(date)
  },
  getDateTime (date) {
    if (date == undefined) {
      date = new Date()
    }
    return date.getFullYear() + '-'
      + ((date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1))
      + '-' + date.getDate()
      + ' ' + date.getHours()
      + ':' + date.getMinutes()
      + ':' + (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
  },

  objDelIndex(obj, index) {
    var tmp = {};
    for (var i in obj) {
      if (i != index) {
        tmp[i] = obj[i]
      }
    }
    return tmp;
  },

  objDelValue(obj, value) {
    var tmp = {};
    for (var i in obj) {
      if (obj[i] != value) {
        tmp[i] = obj[i]
      }
    }
    return tmp;
  },


  arrayDelIndex(array, index) {
    var tmp = [];
    array.map(function (data, i) {
      if (i != index) {
        tmp.push(data)
      }
    })
    return tmp;
  },

  arrayDelValue(array, value) {
    var tmp = [];
    array.map(function (data, i) {
      if (data != value) {
        tmp.push(data)
      }
    })
    return tmp;
  },

  isInArray(val, array) {
    if (!this.isTrue(array)) {
      return false
    }
    for (var i in array) {
      if (array[i] == val) {
        return true;
      }
    }
    return false;
  },
  arrayReplaceValue(array, find, replace) {
    var tmp = [];
    array.map(function (data, i) {
      if (data != find) {
        tmp.push(data)
      } else {
        tmp.push(replace)
      }
    })
    return tmp;
  },
  setLocData (key,val) {
    localStorage.setItem(key,JSON.stringify(val))
  },
  getLocData(key){
    try {
      return JSON.parse(localStorage.getItem(key))
    }catch (e) {
      return (localStorage.getItem(key))
    }
  },
  clearLocData(key){
    localStorage.removeItem(key)
  },
  clearAllLocData(){
    localStorage.clear()
  },
  showToast(message){
    vue.$toast.message(message)
  }
}
